﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2006
' by Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
 */

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Xml;
using System.Web;
using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Search;

namespace Triax.Modules.Department
{
    /// -----------------------------------------------------------------------------
    ///<summary>
    /// The Controller class for the Publication
    /// </summary>
    /// <remarks>
    /// </remarks>
    /// <history>
    /// </history>
    /// -----------------------------------------------------------------------------
    public class PublicationController : ISearchable, IPortable
    {

    #region Constructors

        public PublicationController()
        {
        }

    #endregion

    #region Public Methods

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// adds an object to the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="objPublication">The Publication object</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public void AddPublication(Publication objPublication)
        {
           // if (objPublication.PublicationName.Trim() != "")
            {
                DataProvider.Instance().AddPublication(objPublication.ModuleId,
                    
objPublication.ContractTemplateID,
objPublication.TenAnPham,
objPublication.TacGia,
objPublication.DichGia,
objPublication.SoTrang,
objPublication.KhoGiay,
objPublication.Bia,
objPublication.SoLuongIn,
objPublication.QuyCach,
objPublication.NoiDung,
objPublication.SoDangKy,
objPublication.DonGia,
objPublication.TongTien,
objPublication.MaSoISBN,
objPublication.Noidungkhac,
objPublication.IsXuatBan,
objPublication.IsPrint,
objPublication.SoQuyetDinhXB,
objPublication.NgayQDXB,
objPublication.NguoiKy,
objPublication.InsertDate,
objPublication.UpdateDate,
objPublication.CreateByUser,
objPublication.UpdateByUser,
objPublication.IsDelete,
objPublication.IsLuuChieu,
objPublication.SoXuatBan,
objPublication.TempInt1,
objPublication.TempInt2,
objPublication.TempInt3,
objPublication.TempInt4,
objPublication.TempStr1,
objPublication.TempStr2,
objPublication.TempStr3,
objPublication.TempStr4,
objPublication.TempDate1,
objPublication.TempDate2,
objPublication.SoluongDatin,
objPublication.SoLuongPhatHanh,
objPublication.Filebientap,
objPublication.FIleString1,
objPublication.FIleString2,
objPublication.FIleString3,
objPublication.FIleString4,
objPublication.FIleString5,
objPublication.FIleString6,
objPublication.FIleString7,
objPublication.FIleString8,
objPublication.FIleString9,
objPublication.FIleString10,
objPublication.CheckGiamDoclan1,
objPublication.CheckGiamDoclan2,
objPublication.CheckGiamDoclan3,
objPublication.CheckGiamDoclan4,
objPublication.CheckGiamDoclan5,
objPublication.Checkbientaplan1,
objPublication.Checkbientaplan2,
objPublication.Checkbientaplan3,
objPublication.Checkbientaplan4,
objPublication.Checkbientaplan5,
objPublication.Checkbientaplan6


                    );
            }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// deletes an object from the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ModuleId">The Id of the module</param>
        /// <param name="ItemId">The Id of the item</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public void DeletePublication(int ModuleId, int PublicationId) 
        {
            DataProvider.Instance().DeletePublication(ModuleId,PublicationId);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// gets an object from the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="moduleId">The Id of the module</param>
        /// <param name="ItemId">The Id of the item</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public Publication GetPublication(int ModuleId, int PublicationId)
        {
            return CBO.FillObject<Publication>(DataProvider.Instance().GetPublication(ModuleId, PublicationId));
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// gets an object from the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="moduleId">The Id of the module</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public List<Publication> GetPublications(int ModuleId)
        {
            return CBO.FillCollection< Publication >(DataProvider.Instance().GetPublications(ModuleId));
        }

        public List<Publication> GetPublicationsByCond(int ModuleId, string cond,string sql)
        {
            return CBO.FillCollection<Publication>(DataProvider.Instance().GetPublicationsByCond(ModuleId,cond,sql));
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// saves an object to the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="objPublication">The Publication object</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public void UpdatePublication(Publication objPublication)
        {
           // if (objPublication.PublicationName.Trim() != "")
            {
                DataProvider.Instance().UpdatePublication(objPublication.ModuleId, 
                   
objPublication.PublicationID,
objPublication.ContractTemplateID,
objPublication.TenAnPham,
objPublication.TacGia,
objPublication.DichGia,
objPublication.SoTrang,
objPublication.KhoGiay,
objPublication.Bia,
objPublication.SoLuongIn,
objPublication.QuyCach,
objPublication.NoiDung,
objPublication.SoDangKy,
objPublication.DonGia,
objPublication.TongTien,
objPublication.MaSoISBN,
objPublication.Noidungkhac,
objPublication.IsXuatBan,
objPublication.IsPrint,
objPublication.SoQuyetDinhXB,
objPublication.NgayQDXB,
objPublication.NguoiKy,
objPublication.InsertDate,
objPublication.UpdateDate,
objPublication.CreateByUser,
objPublication.UpdateByUser,
objPublication.IsDelete,
objPublication.IsLuuChieu,
objPublication.SoXuatBan,
objPublication.TempInt1,
objPublication.TempInt2,
objPublication.TempInt3,
objPublication.TempInt4,
objPublication.TempStr1,
objPublication.TempStr2,
objPublication.TempStr3,
objPublication.TempStr4,
objPublication.TempDate1,
objPublication.TempDate2,
objPublication.SoluongDatin,
objPublication.SoLuongPhatHanh,
objPublication.Filebientap,
objPublication.FIleString1,
objPublication.FIleString2,
objPublication.FIleString3,
objPublication.FIleString4,
objPublication.FIleString5,
objPublication.FIleString6,
objPublication.FIleString7,
objPublication.FIleString8,
objPublication.FIleString9,
objPublication.FIleString10,
objPublication.CheckGiamDoclan1,
objPublication.CheckGiamDoclan2,
objPublication.CheckGiamDoclan3,
objPublication.CheckGiamDoclan4,
objPublication.CheckGiamDoclan5,
objPublication.Checkbientaplan1,
objPublication.Checkbientaplan2,
objPublication.Checkbientaplan3,
objPublication.Checkbientaplan4,
objPublication.Checkbientaplan5,
objPublication.Checkbientaplan6



                    );
            }
        }
        // End kết hợp xử lý
    #endregion

    #region Optional Interfaces

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// GetSearchItems implements the ISearchable Interface
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ModInfo">The ModuleInfo for the module to be Indexed</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public SearchItemInfoCollection GetSearchItems(ModuleInfo ModInfo)
        {
            SearchItemInfoCollection SearchItemCollection = new SearchItemInfoCollection();
            List<Publication> colPublications  = GetPublications(ModInfo.ModuleID);

            foreach (Publication objPublication in colPublications)
            {
                if(objPublication != null)
                {
                    SearchItemInfo SearchItem = new SearchItemInfo( );
                    SearchItemCollection.Add(SearchItem);
                }
            }

            return SearchItemCollection;
        }


        /// -----------------------------------------------------------------------------
        /// <summary>
        /// ExportModule implements the IPortable ExportModule Interface
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ModuleID">The Id of the module to be exported</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public string ExportModule(int ModuleID)
        {
            string strXML = "";
            List<Publication> colPublications  = GetPublications(ModuleID);

            if (colPublications.Count != 0)
            {
                strXML += "<Publications>";
                foreach (Publication objPublication in colPublications)
                {
                    strXML += "<Publication>";
                    strXML += "<content>" + XmlUtils.XMLEncode(objPublication.TempStr1) + "</content>";
                    strXML += "</Publication>";
                }
                strXML += "</Publications>";
            }

            return strXML;
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// ImportModule implements the IPortable ImportModule Interface
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ModuleID">The Id of the module to be imported</param>
        /// <param name="Content">The content to be imported</param>
        /// <param name="Version">The version of the module to be imported</param>
        /// <param name="UserId">The Id of the user performing the import</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public void ImportModule(int ModuleID, string Content, string Version, int UserId)
        {
            XmlNode xmlPublications = Globals.GetContent(Content, "Publications");

            foreach (XmlNode xmlPublication in xmlPublications.SelectNodes("Publication"))
            {
                Publication objPublication = new Publication();

                objPublication.ModuleId = ModuleID;
            //    objPublication.PublicationName = xmlPublication.SelectSingleNode("content").InnerText;
          //      objPublication.CreatedByUser = UserId;
                AddPublication(objPublication);
            }

}

    #endregion

    }
}

